
clear
set more off

global exper need4
global educ needbd_plus

global dto "change_openings_per_emp"
global initial "initialneed"
global level2000 "avgageexp"
*global covars    "initialneed change_openings_per_emp avgageexp"
global covars    "initialneed avgageexp"
global stdcovars "stdinitialneed stdavgageexp stdchange_openings_per_emp"

global occfe "i.occsoc_num"
global stfe "i.statefip"
global timefe "b2012.year"

global styearfe "i.styear"
global occyearfe "i.occyear"

global restric "if minto>15 "

global flow "\parbox[c]{1.8cm}{\centering "
global lte "$\leq$"
global gte "$\geq$"

global weight "[w=occshare_state]"

use "BGT_2007_2010_2012_withvars_021716_mechanisms.dta"

set more off, perm
set matsize 1000
********************************************************************************

drop if inlist(statefip,2,15)

sort statefip
tempfile a
save `a', replace

keep statefip vet_bplf1yr vet_stlf1yr year
duplicates drop
keep if year==2007
drop year
egen totalvet = sum(vet_stlf1yr)
egen totalvet_bp=sum(vet_bplf1yr)
g vetratio = vet_stlf1yr/totalvet
g vetratio_bp=vet_bplf1yr/totalvet_bp
keep statefip vetratio*
sort statefip
merge 1:m statefip using `a', nogen keep(match)

eststo clear
tsset

* Modify explanatory variables
g nat_vet_change = ln(predicted_total/L2.predicted_total)
replace nat_vet_change=ln(predicted_total/L3.predicted_total) if nat_vet_change==.

g log_vet_var= nat_vet_change*vetshare_vsoe* vetratio
g log_vet_var_bp =nat_vet_change*vetshare_vsoe* vetratio_bp

summ dvet_supdem_bgt_bp_predic,d
replace dvet_supdem_bgt_bp_predic=. if dvet_supdem_bgt_bp_predic>r(p95) | dvet_supdem_bgt_bp_predic<r(p5)

summ dvet_supdem_bgt_bp_predic,d
replace dvet_supdem_bgt_bp_predic=. if dvet_supdem_bgt_bp_predic>r(p95) | dvet_supdem_bgt_bp_predic<r(p5)


summ dHWOLsupdemratebroad,d
replace dHWOLsupdemratebroad=. if dHWOLsupdemratebroad>r(p95) | dHWOLsupdemratebroad<r(p5)

summ dBGTsupdemratebroad,d
replace dBGTsupdemratebroad=. if dBGTsupdemratebroad>r(p95) | dBGTsupdemratebroad<r(p5)

summ dvet_supdem_bgt,d
replace dvet_supdem_bgt=. if dvet_supdem_bgt>r(p95) | dvet_supdem_bgt<r(p5)


foreach unemp in du dubd {

eststo clear

foreach var in neednoedu needhs needsc needbd needgd needbd_plus    {
	
	if "`var'"!="$educ"  {
	eststo, addscalars(ar3 e(r2_a)): reg d`var' `unemp' $weight $restric , cl(state)
		estadd local baseline "No", replace
		estadd local occyrfe "No", replace
		
	}
	
	if "`var'"=="$educ"  {	
		capture drop avgageexp
		gen avgageexp=bdshare2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		
				eststo, addscalars(ar3 e(r2_a)):  areg d`var' `unemp'  $covars  $weight $restric  , cl(state) a(occyear)
				estadd local baseline "Yes", replace
				estadd local occyrfe "Yes", replace
			}
	}



}


foreach unemp in du du35plus {

eststo clear

foreach var in needna need0to2  need2to4  need4to7 need7to15 need4    {
	
	
	if "`var'"!="$exper"  {
	eststo, addscalars(ar3 e(r2_a)): reg d`var' `unemp' $weight $restric , cl(state)
		estadd local baseline "No", replace
		estadd local occyrfe "No", replace
		
	}
	
	if "`var'"=="$exper"  {	
		capture drop avgageexp
		gen avgageexp=avgage2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		
				eststo, addscalars(ar3 e(r2_a)):  areg d`var' `unemp'  $covars  $weight $restric  , cl(state) a(occyear)
				estadd local baseline "Yes", replace
				estadd local occyrfe "Yes", replace
			}
	}

}


********************************************************************************

foreach var in $educ $exper {

if "`var'"=="$educ" {
		capture drop avgageexp
		gen avgageexp=bdshare2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		capture drop dubdage
		gen dubdage=dubd
	}

	if "`var'"=="$exper" {
		capture drop avgageexp
		gen avgageexp=avgage2000
		capture drop initialneed
		gen initialneed=initial_`var'07
		capture drop dubdage
		gen dubdage=du35plus
	}

foreach unemp in dHWOLsupdemratebroad dBGTsupdemratebroad  {
eststo clear

	eststo, addscalars(ar3 e(r2_a)): reghdfe d`var' `unemp'  $covars $weight $restric , a(occyear) vce(cluster statefip)
		estadd local occyrfe "Yes", replace
		estadd local statefe "No", replace
		estadd local occstfe "No", replace
		estadd local baseline "Yes", replace
		
	eststo, addscalars(ar3 e(r2_a)): reghdfe d`var' `unemp'  $covars $weight $restric , a(occyear statefip) vce(cluster statefip)
		estadd local occyrfe "Yes", replace
		estadd local statefe "Yes", replace
		estadd local occstfe "No", replace
		estadd local baseline "Yes", replace
		
		eststo, addscalars(ar3 e(r2_a)): reghdfe d`var' `unemp'  $covars $weight $restric , a(occyear panelid) vce(cluster statefip)
		estadd local occyrfe "Yes", replace
		estadd local statefe "No", replace
		estadd local occstfe "Yes", replace
		estadd local baseline "Yes", replace	


}
}



eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus du $weight $restric , cl(state)
estadd local baseline "No", replace
estadd local occyrfe "No", replace

eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus du year $weight $restric , cl(state)
estadd local baseline "No", replace
estadd local occyrfe "No", replace
		
	
capture drop avgageexp
gen avgageexp=bdshare2000
capture drop initialneed
gen initialneed=initial_needbd_plus07
		
eststo, addscalars(ar3 e(r2_a)):  areg dneedbd_plus du $covars  $weight $restric  , cl(state) a(occyear)
estadd local baseline "Yes", replace
estadd local occyrfe "Yes", replace


eststo, addscalars(ar3 e(r2_a)): reg dneed4 du $weight $restric , cl(state)
estadd local baseline "No", replace
estadd local occyrfe "No", replace

eststo, addscalars(ar3 e(r2_a)): reg dneed4 du year $weight $restric , cl(state)
estadd local baseline "No", replace
estadd local occyrfe "No", replace
		
capture drop avgageexp
gen avgageexp=avgage2000
capture drop initialneed
gen initialneed=initial_need407
		
eststo, addscalars(ar3 e(r2_a)):  areg dneed4 du  $covars  $weight $restric  , cl(state) a(occyear)
estadd local baseline "Yes", replace
estadd local occyrfe "Yes", replace



eststo, addscalars(ar3 e(r2_a)): reg dneedbd_plus dBGTsupdemratebroad year $weight $restric , cluster(state)
		estadd local occyrfe "No", replace
		estadd local statefe "No", replace
		estadd local occstfe "No", replace
		estadd local baseline "No", replace


eststo, addscalars(ar3 e(r2_a)): reg dneed4 dBGTsupdemratebroad year $weight $restric , cluster(state)
		estadd local occyrfe "No", replace
		estadd local statefe "No", replace
		estadd local occstfe "No", replace
		estadd local baseline "No", replace


